package leetcode101.ch2;

import java.util.Arrays;

//LC 605
public class CanPlaceFlowers {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int[] newBed = new int[flowerbed.length + 2];
        // newBed = [0] + flowerbed + [0]
        System.arraycopy(flowerbed, 0, newBed, 1, flowerbed.length);
        int count = 0;
        int zeroCount = 0;
        System.out.println(Arrays.toString(newBed));
        for (int i = 0; i < newBed.length; i++) {
            if (newBed[i] == 0) {
                zeroCount++;
            }else {
                count += (zeroCount - 1) / 2;
                zeroCount = 0;
            }
        }
        //如果最后一位是0
        count +=  (zeroCount - 1) / 2;
        return count >= n;
    }

    public static void main(String[] args) {
        int[] flowerbed = {1,0,0,0,1,0,0};
        boolean b = new CanPlaceFlowers().canPlaceFlowers(flowerbed, 2);
        System.out.println(b);
    }
}
